home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload Trio 2
/
Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO
/
dir37
/
splt-bat.zip
/
README
< prev
next >
Wrap
Text File
|
1993-03-26
|
13KB
|
440 lines
TEST.BAT and EDIT.BAT README File
1) TEST.BAT is a DOS batch routine to split the name of an input file into
three components: pathname, filename, and extension. It works because of the
FOR command's peculiar behaviour when a "/" is placed in front of the value in
the brackets, i.e. FOR %%a IN (/VALUE) DO. This command chops off the first
letter in VALUE leaving ALUE. With this feature it is possible to "count" the
length of a string, and chop off unwanted information. The batch, however,
cannot handle wildcards. If you are curious to see how it works search out the
REM's which come before ECHO statements and delete them, and then run the
batch, you will see how the various components are generated. If you do not
have a color monitor or do not have ANSI.SYS or an equivalent installed
remove the ANSI codes in the last ECHO statement, i.e. the "B
"
One warning, even on a 486/33 machine, processing a file with a long
pathname can take a few seconds, it might be extremely slow on a slower
machine.
Usage: Type TEST [pathname]\filename.ext. This batch file will not test
to see if you entered a filename which is valid by DOS standards, so if you
wish to really test it make sure you enter a valid name (however, it is not
necessary that you have a file with that name on your system).
@ECHO OFF
REM If no file specified go to end
IF "%1"=="" GOTO End
REM Converts input to upper case. Not necessary but I used it to get the
REM output at the end in uppercase. This particular routine, except the line
REM reading SET Pathname= should be removed. %UpCase% should then be be
REM changed to %1. It should also be changed everywhere else in the file.
REM These places indicated by asterisks.
SET OldPath=%Path%
PATH=%1
SET UpCase=%Path%
SET Path=%OldPath%
SET PathName=%UpCase%
SET OldPath=
REM this routine determines if a path was attached to the file specified.
REM If no path was indicated the batch then branches to SetExt.
:PathSeek
SET Prev=%PathName%
FOR %%a IN (/%pathName%) DO SET PathName=%%a
IF "\%PathName%"=="%Prev%" GOTO PathFound
SET Count=%Count%x
IF NOT "%PathName%"=="%Prev%" GOTO PathSeek
REM *****************
SET FileName=%UpCase%
SET PathName=
GOTO SetExt
:PathFound
REM **************** Little square box entered with Alt-254 on numeric keypad
SET PathName=%UpCase%■
SET Count=
SET BackCount=
REM this routine determines the path's length.
:PathLength
SET Prev=%PathName%
FOR %%a IN (/%PathName%) DO SET PathName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackSlash
FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO FileSetup
SET Count=%Count%x
REM ECHO Value of PathName is %PathName%
REM ECHO Value of Count %Count%
GOTO PathLength
:BackSlash
REM ECHO VALUE OF PATHNAME IS %PathName%
SET BackCount=%BackCount%x
GOTO PathLength
:FileSetup
REM *****************
SET FileName=%UpCase%
SET BkCount=
REM This routine gets the filename with its extension.
:FileGet
SET Prev=%FileName%
FOR %%a IN (/%FileName%) DO SET FileName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO Back
REM ECHO Value of FileName is %FileName%
GOTO FileGet
:Back
REM ECHO VALUE OF FileName IS %FileName%
SET BkCount=%BkCount%x
IF NOT "%BkCount%"=="%BackCount%" GOTO FileGet
SET TempFile=%FileName%■
SET Count=
REM this routine gets the file and its extension's length.
:FileLength
SET Prev=%TempFile%
FOR %%a IN (/%TempFile%) DO SET TempFile=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO PathSetup
SET Count=%Count%x
REM ECHO Value of TempFile is %TempFile%
REM ECHO Value of Count is %Count%
GOTO FileLength
:PathSetup
SET Count=%Count%x
REM *****************
SET PathName=%UpCase%
SET BkCount=
SET File=
SET TempFile=
REM the following routines will get the files pathname.
:PathGet1
SET Prev=%PathName%
FOR %%a IN (/%PathName%) DO SET PathName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a%PathName%"=="%Prev%" SET
PathName=%PathName%%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackAgain
REM ECHO Value of PathName is %PathName%
GOTO PathGet1
:BackAgain
REM ECHO VALUE OF PATHNAME IS %PathName%
SET BkCount=%BkCount%x
IF NOT "%BkCount%"=="%BackCount%" GOTO PathGet1
SET Counter=
:PathGet2
FOR %%a IN (/%PathName%) DO SET PathName=%%a
SET Counter=%Counter%x
REM ECHO VALUE OF PATHNAME IS %PathName%
IF NOT "%Counter%"=="%Count%" GOTO PathGet2
SET Counter=
SET Count=
SET BkCount=
SET BackCount=
:SetExt
SET Ext=%FileName%
REM this routine checks to see if the specified file had an extension.
REM This comes from Prof. Timo Salmi's collection of batch files TSBAT*.ZIP
REM a good primer for batch programming.
:ExtCheck
SET Prev=%Ext%
FOR %%a IN (/%Ext%) DO SET Ext=%%a
IF ".%Ext%"=="%Prev%" GOTO ExtFound
REM ECHO Value of Ext is %Ext%
SET Count=%Count%x
IF NOT "%Ext%"=="%Prev%" GOTO ExtCheck
SET Name=%FileName%
SET Ext=
GOTO NoExt
:ExtFound
SET Prev=
SET Len=
SET NewExt=%Ext%■
REM this routine determines the length of the extension.
:FindLen
FOR %%a IN (/%NewExt%) DO SET NewExt=%%a
SET Len=%Len%x
IF NOT "%NewExt%"=="■" GOTO FindLen
SET NewExt=
SET Name=%FileName%
SET NewCount=
REM the following routines chop off the extension to get the files's name.
:ChopExt
SET Prev=%Name%
FOR %%a IN (/%Name%) DO SET Name=%%a
FOR %%a IN (/%Prev%) DO IF "%%a%Name%"=="%Prev%" SET Name=%Name%%%a
REM ECHO Value of Name is %Name%
SET NewCount=%NewCount%x
IF NOT "%Count%"=="%NewCount%" GOTO ChopExt
SET NewCount=
SET NewLen=
:GetName
SET Prev=%Name%
FOR %%a IN (/%Name%) DO SET Name=%%a
REM ECHO Value of Name is %Name%
SET NewLen=%NewLen%x
IF NOT "%NewLen%"=="%Len%x" GOTO GetName
SET NewLen=
SET Len=
:NoExt
SET FileName=
SET Count=
SET Prev=
IF NOT "%PathName%"=="" SET PathState=full Path Name is "%PathName%",
IF NOT "%Name%"=="" SET NameState=Name is "%Name%"
IF NOT "%Ext%"=="" SET ExtState=, and Extension is "%Ext%"
cls
ECHO B
"%UpCase%"'s %PathState% %NameState%%ExtState%
SET PathState=
SET NameState=
SET ExtState=
:End
2) EDIT.BAT is a batch application which uses the TEST.BAT routine. DOS 5.0's
EDIT is a much better editor than EDLIN but it does not create a backup of a
file that you edit. In this regard EDLIN has the following features, if you
make changes to an existing file it creates a .BAK file, if you open a file
but do not make any changes it does not create a backup file. If you load a
file with the name FILE.EXT and a FILE.BAK backup file already exists in the
current directory EDIT.BAT will not destroy FILE.BAK if you do not make any
changes to FILE.EXT. EDLIN also creates its backup files in the directory
where the edited files reside. EDIT.BAT will do all of these things, with the
exception of the last. It creates its .BAK files in the current directory.
This, however, can easily be changed by modifying the routine RenBak which
creates the .BAK file (See REM statement for details).
This batch file when determining if a file has been changed creates some
temporary files (in the routine labelled FilComp). I direct them to my ramdisk
"E:", you should replace this path with the directory in which you wish to
have them created. If the batch terminates normally it will delete all its
temporary files, however, if it should terminate abnormally having the
temporary files on a ramdisk means that they will be deleted upon next reboot,
not leaving any extra files on disk.
This batch file also uses ANSI codes so if you do not have a color
monitor or do not have ANSI.SYS or an equivalent loaded you should remove the
codes i.e. 23H
and
on line 10.
This batch file assumes that EDIT.COM is on C drive in \DOS directory.
If you should have yours in another directory you will have to modify the path
in the routine labelled LoadEdit.
Usage: EDIT [pathname]\filename.ext
@ECHO OFF
IF "%1"=="" GOTO LoadEdit
IF NO EXIST %1 GOTO LoadEdit
SET PathName=%1
CLS
SET OldPath=%Path%
PATH=%1
SET UpCase=%Path%
SET Path=%OldPath%
ECHO 23H
Please wait; loading
%UpCase%
SET OldPath=
SET UpCase=
:PathSeek
SET Prev=%PathName%
FOR %%a IN (/%pathName%) DO SET PathName=%%a
IF "\%PathName%"=="%Prev%" GOTO PathFound
SET Count=%Count%x
IF NOT "%PathName%"=="%Prev%" GOTO PathSeek
SET FileName=%1
SET PathName=
GOTO SetExt
:PathFound
SET PathName=%1■
SET Count=
SET BackCount=
:PathLength
SET Prev=%PathName%
FOR %%a IN (/%PathName%) DO SET PathName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackSlash
FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO FileSetup
SET Count=%Count%x
REM ECHO Value of PathName is %PathName%
REM ECHO Value of Count %Count%
GOTO PathLength
:BackSlash
REM ECHO VALUE OF PATHNAME IS %PathName%
SET BackCount=%BackCount%x
GOTO PathLength
:FileSetup
SET FileName=%1
SET BkCount=
:FileGet
SET Prev=%FileName%
FOR %%a IN (/%FileName%) DO SET FileName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO Back
REM ECHO Value of FileName is %FileName%
GOTO FileGet
:Back
REM ECHO VALUE OF FileName IS %FileName%
SET BkCount=%BkCount%x
IF NOT "%BkCount%"=="%BackCount%" GOTO FileGet
SET TempFile=%FileName%■
SET Count=
:FileLength
SET Prev=%TempFile%
FOR %%a IN (/%TempFile%) DO SET TempFile=%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="■" GOTO PathSetup
SET Count=%Count%x
REM ECHO Value of TempFile is %TempFile%
REM ECHO Value of Count is %Count%
GOTO FileLength
:PathSetup
SET Count=%Count%x
SET PathName=%1
SET BkCount=
SET File=
SET TempFile=
:PathGet1
SET Prev=%PathName%
FOR %%a IN (/%PathName%) DO SET PathName=%%a
FOR %%a IN (/%Prev%) DO IF "%%a%PathName%"=="%Prev%" SET
PathName=%PathName%%%a
FOR %%a IN (/%Prev%) DO IF "%%a"=="\" GOTO BackAgain
REM ECHO Value of PathName is %PathName%
GOTO PathGet1
:BackAgain
REM ECHO VALUE OF PATHNAME IS %PathName%
SET BkCount=%BkCount%x
IF NOT "%BkCount%"=="%BackCount%" GOTO PathGet1
SET Counter=
:PathGet2
FOR %%a IN (/%PathName%) DO SET PathName=%%a
SET Counter=%Counter%x
REM ECHO VALUE OF PATHNAME IS %PathName%
IF NOT "%Counter%"=="%Count%" GOTO PathGet2
SET Counter=
SET Count=
SET BkCount=
SET BackCount=
:SetExt
SET Ext=%FileName%
:ExtCheck
SET Prev=%Ext%
FOR %%a IN (/%Ext%) DO SET Ext=%%a
IF ".%Ext%"=="%Prev%" GOTO ExtFound
REM ECHO Value of Ext is %Ext%
SET Count=%Count%x
IF NOT "%Ext%"=="%Prev%" GOTO ExtCheck
SET Name=%FileName%
SET Ext=
GOTO NoExt
:ExtFound
SET Prev=
SET Len=
SET NewExt=%Ext%■
:FindLen
FOR %%a IN (/%NewExt%) DO SET NewExt=%%a
SET Len=%Len%x
IF NOT "%NewExt%"=="■" GOTO FindLen
SET NewExt=
SET Name=%FileName%
SET NewCount=
:ChopExt
SET Prev=%Name%
FOR %%a IN (/%Name%) DO SET Name=%%a
FOR %%a IN (/%Prev%) DO IF "%%a%Name%"=="%Prev%" SET Name=%Name%%%a
REM ECHO Value of Name is %Name%
SET NewCount=%NewCount%x
IF NOT "%Count%"=="%NewCount%" GOTO ChopExt
SET NewCount=
SET NewLen=
:GetName
SET Prev=%Name%
FOR %%a IN (/%Name%) DO SET Name=%%a
REM ECHO Value of Name is %Name%
SET NewLen=%NewLen%x
IF NOT "%NewLen%"=="%Len%x" GOTO GetName
SET NewLen=
SET Len=
:NoExt
SET FileName=
SET Count=
SET Prev=
:CopyTemp
COPY %1 %Name%.$$$>NUL
SET Exists=1
:LoadEdit
C:\DOS\EDIT %1
IF "%1"=="" GOTO End
IF "%Exists%"=="" GOTO End
:FilComp
FC %1 %Name%.$$$>E:\TEMP$$$$.$$$
FIND /N "FC: no differences encountered" < E:\TEMP$$$$.$$$ > E:\COMP$$$.$$$
IF EXIST E:\TEMP$$$$.$$$ ERASE E:\TEMP$$$$.$$$
COPY E:\COMP$$$.$$$ E:\COMP$$$$.$$$ > NUL
IF EXIST E:\COMP$$$$.$$$ ERASE E:\COMP$$$.$$$
IF NOT EXIST E:\COMP$$$$.$$$ GOTO RenBak
IF EXIST %Name%.$$$ ERASE %Name%.$$$
GOTO End
:RenBak
IF EXIST %Name%.BAK ERASE %Name%.BAK
IF EXIST %Name%.$$$ REN %Name%.$$$ %Name%.BAK
IF EXIST E:\COMP$$$$.$$$ ERASE E:\COMP$$$$.$$$
REM If you should wish to have your backup files created in the directory
REM where the edited file resides change remove the REM's in front of the
REM of the next few lines and delete or REM out the three lines above begin-
REM ning with IF EXIST
REM COPY %Name%.$$$ %PathName%%Name%.BAK
REM ERASE %NAME%.$$$
COPY
:End
SET Pathname=
SET Name=
SET Ext=
SET Exists=
Hope you enjoy these two batch files. If you have any questions and comments
you can reach me at:
Daniel Marier
262A Vaughan Rd
Toronto, Ontario
Canada M6C 2N1
until mid-May '93.